package com.ruoyi.machine.base.accessory.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.machine.base.accessory.domain.Accessory;
import com.ruoyi.machine.base.accessory.service.IAccessoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备附件信息
 * 控制层
 */

@RestController
@RequestMapping("/machine/accessory")
@Api(value = "设备附件信息管理模块", tags = "设备附件信息接口")
public class AccessoryController extends BaseController {

    @Autowired
    private IAccessoryService accessoryService;

    /**
     * 获取附属设备信息列表
     * @param accessory
     * @return
     */
    @ApiOperationSupport(includeParameters = {"Accessory.accessoryId", "Accessory.accessoryName"})
    @ApiOperation(value = "获取供应商信息列表",notes = "查询所有供应商信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Accessory accessory) {

        startPage();

        List<Accessory> accessoryList = accessoryService.selectAccessoryList(accessory);

        return getDataTable(accessoryList);
    }

    /**
     * 导出附属设备信息
     * @param accessory
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody Accessory accessory) {

        List<Accessory> accessoryList = accessoryService.selectAccessoryList(accessory);

        ExcelUtil<Accessory> util = new ExcelUtil<>(Accessory.class);

        return util.exportExcel(accessoryList, "附属设备信息数据");
    }

    /**
     * 新增附属设备
     * @param accessory
     * @return
     */
    @ApiOperation(value = "新增附属设备", notes = "新增附属设备")
    @ApiImplicitParam(name = "accessory", value = "新增附属设备", dataType = "Accessory")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody Accessory accessory) {
        return toAjax(accessoryService.insertAccessory(accessory));
    }

    /**
     * 修改附属设备
     * @param accessory
     * @return
     */
    @ApiOperation(value = "修改附属设备", notes = "修改附属设备")
    @ApiImplicitParam(name = "accessory", value = "修改附属设备", dataType = "Accessory")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody Accessory accessory) {
        return toAjax(accessoryService.updateAccessory(accessory));
    }

    /**
     * 删除附属设备信息
     * @param accessory
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Accessory accessory) {
        return toAjax(accessoryService.deleteAccessory(accessory));
    }
}
